<?
/*
 * Copyright 2004-2005 Sigve Indregard.
 *
 * This file is part of Laivsys.
 *
 * Laivsys is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Laivsys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Laivsys; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * $Id: admins.php 6 2005-07-11 23:14:47Z say $
 */
 
include("../db.php");
include("auth.php");
include("top.php");

if ($_REQUEST['process'] == 'true') {
	$id=$_REQUEST['id'];
	if (! is_numeric($id)) {
		die("Your ID is phuxxored up");
	}

	$action=$_REQUEST['action'];
	$user=$_REQUEST['username'];
	$pass=$_REQUEST['password'];

	$sql="";
	
	if ($action == 'Legg til')
		$sql="INSERT INTO admins (Username, Password) VALUES ('$user', '$pass')";
	elseif ($action == 'Slett')
		$sql="DELETE FROM admins WHERE ID=$id";
	elseif ($action == 'Oppdater')
		$sql="UPDATE admins SET Username='$user', Password='$pass' WHERE ID=$id";
	
	if (! empty($sql) ) {
		mysql_query($sql);
		if (mysql_errno())
			echo "En feil oppstod: ".mysql_error();
		else
			echo "Handlingen '$action' ble gjennomf�rt uten feil.";
	}
}
?>
<h1>Admins</h1>
<table>
	<tr>
		<th>ID</th>
		<th>Brukernavn</th>
		<th>Passord</th>
	</tr>
<?
$sql="SELECT * FROM admins ORDER BY username";
$admins=mysql_query($sql);
while ($admin=mysql_fetch_assoc($admins)) {
	?>
	<form method="post" action="admins.php">
	<input type="hidden" name="process" value="true">
	<input type="hidden" name="id" value="<?=$admin['ID']?>">
	<tr>
		<td><?=$admin['ID']?></td>
		<td><input name="username" value="<?=$admin['username']?>"></td>
		<td><input name="password" value="<?=$admin['password']?>" type="password"></td>
		<td><input type="submit" name="action" value="Oppdater"></td>
		<td><input type="submit" name="action" value="Slett"></td>
	</tr>
	</form>
	<?
}
?>
	<form method="post" action="admins.php">
	<input type="hidden" name="process" value="true">
	<input type="hidden" name="id" value="0">
	<tr>
		<td>Ny</td>
		<td><input name="username" value=""></td>
		<td><input name="password" value="" type="password"></td>
		<td><input type="submit" name="action" value="Legg til"></td>
	</tr>
</table>
<?
include("bottom.php");
?>
